<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>$watch 与$filter 过滤器制作数据筛选实例</title>
    <script src="../angular.js"></script>
</head>
<body>
<div ng-app="gg" ng-controller="ctrl">
    搜索: <input type="text" ng-model="search"><br />
    <table border="1" width="500px">
        <tr>
            <th>编号</th>
            <th>点击数</th>
            <th>标题</th>
        </tr>
        <tr ng-repeat="(k,v) in lists" align="center">
            <td>{{v.id}}</td>
            <td>{{v.click}}</td>
            <td>{{v.title}}</td>
        </tr>
    </table>
</div>

<script>
    var mod = angular.module('gg', []);
    mod.controller('ctrl', ['$scope', '$filter', function ($scope, $filter) {
        $scope.data = [
            {id: 1 ,click : 100, title : '美文'},
            {id: 2 ,click : 80, title : '英语'},
            {id: 3 ,click : 150, title : '高数'}
        ];

        //临时数据
        $scope.lists = $scope.data;
        $scope.$watch('search', function (news, olds) {

            $scope.lists = $filter('filter')($scope.data, news);
            console.log($scope.data);
        })
    }])
</script>
</body>
</html>